package com.second.rbm;

import com.aliyuncs.exceptions.ClientException;
import com.rabbitmq.client.Channel;
import com.second.consts.RabbitConst;
import com.second.util.SmsUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


import java.io.IOException;
import java.util.Map;

@Component
public class SimpleSmsService {
    @RabbitHandler
    @RabbitListener(queues = RabbitConst.SIMPLE_QUEUE)
    public void sendSms(Map<String, String> msgMap, Channel channel, Message message) {
        String phone = msgMap.get("phone");
        String code = msgMap.get("code");
        try {
            System.out.println("phone:" + phone);
            System.out.println("code:" + code);
            SmsUtils.sendSms(phone, code);
            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        } catch (IOException | ClientException e) {
            e.printStackTrace();
        }

    }
}
